//
//  PreviewViewController.m
//  Civacrm
//
//  Created by 王桂敏 on 2017/2/14.
//  Copyright © 2017年 王桂敏. All rights reserved.
//

#import "PreviewViewController.h"

@interface PreviewViewController ()

@property (nonatomic,strong) UIImageView *imageView;

@property (nonatomic,strong) UILabel *titleLabel;

@end

@implementation PreviewViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar setNavigationBarTransparent:YES];
    self.edgesForExtendedLayout = UIRectEdgeTop;
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    [self.navigationController.navigationBar setNavigationBarTransparent:NO];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self initView];
    [self initNetWork];
}

- (void)initView{
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, h(20) + 5, 44, 44);
    [button setImage:[UIImage imageNamed:@"btn_return"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(handButtonAction) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:button];
    
    self.view.backgroundColor = BlackColor;
    self.imageView = [UIImageView imageViewWithFrame:CGRectMake(0, 64, kScreenWidth,kScreenHeight - h(60) - 64) image:nil];
    self.imageView.backgroundColor = ClearColor;
    self.imageView.contentMode = UIViewContentModeScaleAspectFit;
    [self.view addSubview:self.imageView];

    UIView *bgView = [UIView viewWithFrame:CGRectMake(0, getMaxY(self.imageView) - h(20) - h(30), kScreenWidth, h(50)) bgColor:BlackColor];
    bgView.alpha = 0.5;
    [self.view addSubview:bgView];
    
    UIImageView *iconView = [UIImageView imageViewWithFrame:CGRectMake(w(10), getMaxY(self.imageView) - h(10) - h(30), w(37), h(30)) image:@"icon_jigou_touming"];
    [self.view addSubview:iconView];
    
    
    UILabel *nameLabel = [UILabel labelWithTitle:nil frame:CGRectMake(getMaxX(iconView) + w(10), iconView.y, kScreenWidth - w(10) -  getMaxX(iconView) - w(10), iconView.height) font:font(24) textColor:WhiteColor bgColor:ClearColor];
    nameLabel.alpha = 0.5;
    nameLabel.text = self.orgName;
    [self.view addSubview:nameLabel];
    
    self.titleLabel = [UILabel labelWithTitle:nil frame:CGRectMake(w(19), getMaxY(self.imageView), kScreenWidth - w(19) * 2, h(60)) font:font(24) textColor:WhiteColor bgColor:ClearColor];
    [self.view addSubview:self.titleLabel];
}
- (void)handButtonAction{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - networkAndNetworkDelegate -
- (void)initNetWork{
    
    self.params[@"uId"] = self.userID;
    self.params[@"subTaskId"] = self.subTaskId;
    
    [self showIndeterminate];
    [self.manager postWithURL:NET_GETSTUDYRECORD param:self.params delegate:self isEncrypt:NO type:NetWorkingType0];
    
}

- (void)networkingHandleSuccess:(NetworkingHandle *)handle parameters:(NSDictionary *)parameters responseObject:(id)responseObject type:(NetWorkingType)type{
    [self hideHud];
    switch (type) {
        case NetWorkingType0:
        {
            [self.imageView sd_setImageWithURL:[NSURL URLWithString:responseObject[@"studyImg"]] placeholderImage:nil];
            self.titleLabel.text = responseObject[@"studyContent"];
        }
            break;
            
        default:
            break;
    }
    
    
    
}

- (void)networkingHandlefail:(NetworkingHandle *)handle type:(NetWorkingType)type{
    [self hideHud];
}

- (void)networkingHandleWarning:(NetworkingHandle *)handle responseObject:(id)responseObject type:(NetWorkingType)type{
    [self hideHud];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
